package com.example.demo.controller;

import cn.hutool.core.bean.BeanUtil;
import com.example.demo.config.ben.TokenInfoBO;
import com.example.demo.config.ben.TokenStore;
import com.example.demo.entity.DTO.RefreshTokenDTO;
import com.example.demo.entity.VO.TokenInfoVO;
import com.example.demo.result.Result;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

/*
 * @Author:大力王
 * @Date:2024/6/5-05-16:08
 * 开始了
 */
@RestController
@Api(tags = "红-刷新token接口")
@RequestMapping("/token")
public class TokenController {
    @Resource
    private TokenStore tokenStore;

    @PostMapping("/refresh")
    public Result<TokenInfoVO> refreshToken(@Valid @RequestBody RefreshTokenDTO refreshTokenDTO) {
        TokenInfoBO tokenInfoServerResponseEntity = tokenStore
                .refreshToken(refreshTokenDTO.getRefreshToken());
        return Result.success(BeanUtil.copyProperties(tokenInfoServerResponseEntity, TokenInfoVO.class));
    }
}
